//
//  ZSLNavigationController.swift
//  micro_blog
//
//  Created by Mac on 16/9/19.
//  Copyright © 2016年 Mac. All rights reserved.
//

import UIKit

class ZSLNavigationController: UINavigationController,UIGestureRecognizerDelegate
{

    override func viewDidLoad() {
        
        super.viewDidLoad()
        
        //设置边缘手势
        self.interactivePopGestureRecognizer?.delegate = self
        
    }
    
   override func pushViewController(_ viewController: UIViewController, animated: Bool) {
        
        if viewControllers.count > 0
        {
            if viewControllers.count == 1
            {
                let title = viewControllers.first!.title!
                
                viewController.navigationItem.leftBarButtonItem = UIBarButtonItem(title: title, imageName: "navigationbar_back_withtext", target: self, action: #selector(backAction))
                
            }else
            {
                
                viewController.navigationItem.leftBarButtonItem = UIBarButtonItem(title: "返回", imageName: "navigationbar_back_withtext", target: self, action: #selector(backAction))
            }
            
            viewController.title = "当前显示的第\(viewControllers.count + 1)级控制器"
            
        }
        
        super.pushViewController(viewController, animated: animated)
    }
    
    
    func backAction()
    {
        
        popViewController(animated: true)
        
    }
    
    func gestureRecognizerShouldBegin(_ gestureRecognizer: UIGestureRecognizer) -> Bool {
        
        if viewControllers.count == 1
        {
            return false
        }
        
        return true
    }
  
}
